<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <style>
            #tip{
                overflow: hidden;
            }
            ul{
                width: 200px;
                margin: 0px;
                padding: 0px;
                list-style: none;
                overflow: hidden;
            }
            ul>li{
                width: 30px;
                height: 30px;
                text-align: center;
                line-height: 30px;
                margin-left: 5px;
                float: left;
                background-color: red;
                border-radius: 50%;
                color: white;
            }
            #btn{
                position: relative;
                left: 200px;
                top: -28px;
                margin-left: 10px;
            }
        </style>
    </head>
    <body>
        <div id="tip">
            <ul id="ul">
                <li>1</li>
                <li>2</li>
                <li>3</li>
                <li>4</li>
                <li>5</li>
            </ul>
            <button id="btn">换一换</button>
        </div>
        <script>
            var _ul=document.getElementById('ul')
            var _btn=document.getElementById('btn')

            // 执行
            _btn.onclick=function(){
                var newArr=createNum(6)
                var HTML=''
                for(var i=1;i<newArr.length;i++){
                    HTML+='<li>'+newArr[i]+'</li>'
                }
                _ul.innerHTML=HTML
            }

            // 生成随机数
            function random(min,max){
                let int=Math.random()*(max-min+1)
                return Math.floor(int)+min
            }

            // 除重
            function createNum(len){
                var arr=[]
                var i=0
                while (i<len){
                    var int=random(0,32)
                    var strArr=arr.toString()
                    if (strArr.indexOf(int)==-1) {
                        arr.push(int)
                    }else{
                        continue
                    }
                    i++
                }
                return arr
            }
        </script>
    </body>
    </html>
</body>
</html>